<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="shop-info-box">
					<view class="info-item flexWrapNo">
						<view>名称：</view>
						<input placeholder="请输入名称" placeholder-class="placeholderclass" v-model="store_equipment_info.equipment_name" maxlength="10"/>
					</view>
					<view class="info-item">
						<view>台桌视频</view>
						<view class="attachment-box flexWrapNo">
							<view class="attachment-img" v-if="video_url">
								<image :src="video_url+'?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,ar_auto'"></image>
								<image src="../../static/user/close.png" class="close-btn" @tap="deleteVideo"></image>
							</view>
							<view class="add-btn" @tap="chooseVideo()" v-if="!video_url"></view>
						</view>
						<view class="attachment-tips">备注:视频显示在乒个乓自助小程序店铺首页,仅支持MP4格式横屏视频，不超过50M</view>
					</view>
					<view class="info-item">
						<view>台桌图片</view>
						<view class="attachment-box flexWrapNo">
							<view @tap="previewImage(item,imageList)" class="attachment-img"
								v-for="(item,index) in imageList" :key="index">
								<image :src="item"></image>
								<image src="../../static/user/close.png" class="close-btn"
									@tap.stop="deleteImage(index)"></image>
							</view>
							<view class="add-btn" @tap="chooseImage()" v-if="imageList.length<5"></view>
						</view>
						<view class="attachment-tips">备注:图片显示在乒个乓自助小程序店铺首页,仅支持jpg、jpeg、png格式图片</view>
					</view>
					<view class="info-item flexWrap">
						<view class="flexWrapNo" style="flex: 1;">
							<view>类型：</view>
							<picker @change="bindPickerChange" :value="index" :range="array">
								<view class="uni-input">{{array[index]}}</view>
							</picker>
						</view>
						<text class="icon-more"></text>
					</view>
					<block  v-if="index==0">
						<view class="info-item flexWrap">
							<view class="flexWrapNo" style="flex: 1;">
								<view>台桌类型：</view>
								<picker @change="changeTable" :value="tableIndex" :range="tableList" range-key="name">
									<view class="uni-input">{{tableList[tableIndex].name}}</view>
								</picker>
							</view>
							<text class="icon-more"></text>
						</view>
						<view class="info-item flexWrap">
							<view class="flexWrapNo" style="flex: 1;">
								<view>计费方式：</view>
								<picker @change="changePrice" :value="tqpriceIndex" :range="tqpriceList" range-key="name">
									<view class="uni-input">{{tqpriceList[tqpriceIndex].name||'未选择'}}</view>
								</picker>
							</view>
							<text class="icon-more"></text>
						</view>
						<view class="info-item flexWrap" @tap="openAttr">
							<view class="flexWrapNo" style="flex: 1;">
								<view>台桌标签：</view>
								<text style="font-size: 20upx;">{{attrName||'未选择'}}</text>
							</view>
							<text class="icon-more"></text>
						</view>
					</block>
					<block  v-if="index==1">
						<view class="info-item flexWrap">
							<view class="flexWrapNo" style="flex: 1;">
								<view>计费规则：</view>
								<picker @change="changeMahjong" :value="mahjongPriceIndex" :range="mahjong_price_list" range-key="name" v-if="mahjong_price_list.length">
									<view class="uni-input">{{mahjong_price_list[mahjongPriceIndex].name}}</view>
								</picker>
							</view>
							<text class="icon-more"></text>
						</view>
						<view class="info-item flexWrap" @tap="openAttr">
							<view class="flexWrapNo" style="flex: 1;">
								<view>台桌标签：</view>
								<text style="font-size: 20upx;">{{attrName||'未选择'}}</text>
							</view>
							<text class="icon-more"></text>
						</view>
					</block>

					<!-- <view class="info-item flexWrap" @tap="openPicker(0)">
						<view class="flexWrapNo" style="flex: 1;">
							<view>主控开关：</view>
							<text style="font-size: 20upx;" v-if="did">{{resourcesList[value[0]].name}}{{equipmentResources[value[1]].name}} <text v-if="equipmentList.length!=0">{{equipmentList[value[2]].name}}</text> </text>
							<text style="font-size: 24upx;" v-else>未设置</text>
						</view>
						<text class="icon-more"></text>
					</view>
					<view class="info-item flexWrap" @tap="openPicker(1)">
						<view class="flexWrapNo" style="flex: 1;">
							<view>逆向开关：</view>
							<text style="font-size: 20upx;" v-if="dids">{{resourcesLists[reversevalue[0]].name}}{{equipmentResourcess[reversevalue[1]].name}} <text v-if="equipmentLists.length!=0">{{equipmentLists[reversevalue[2]].name}}</text> </text>
							<text style="font-size: 24upx;" v-else>未设置</text>
						</view>
						<text class="icon-more"></text>
					</view>
					<view class="remaks-box">
						备注：主控开关与订单同步通电断电，逆向开关在订单开始时断电，订单结束时通电。（常用于桌底氛围灯和包房门禁）
					</view>
					<view class="info-item flexWrapNo">
						<view>系统音箱SN：</view>
						<input placeholder="请输入" placeholder-class="placeholderclass" v-model="store_equipment_info.sound_sn"/>
					</view>
					<view class="remaks-box">
						备注：SN码位于系统播报音箱底部。
					</view> -->
					
					<view class="info-item flexWrap" @tap="openRollerPicker()">
						<view class="flexWrapNo" style="flex: 1;">
							<view>卷帘：</view>
							<text style="font-size: 24upx;" v-if="curtainStr">{{curtainStr}}</text>
							<text style="font-size: 24upx;" v-else>请选择</text>
						</view>
						<text class="icon-more"></text>
					</view>
					<view class="info-item flexWrapNo" style="align-items: baseline;">
						<view style="flex: none;">美团可用券：</view>
						<view class="select-box" v-if="meituanList.length">
							<view class="select-item flexWrapNo" v-for="(item,index) in meituanList" :key="index" @tap="selectMeituan(index)">
								<image src="../../static/order/select-icon.png" class="select-icon" v-if="item.check"></image>
								<image src="../../static/order/notselect-icon.png" class="select-icon" v-else></image>
								<text>{{item.title}}</text>
							</view>
						</view>
						<view v-else>请先添加美团券</view>
					</view>
					<view class="info-item flexWrapNo" style="align-items: baseline;">
						<view style="flex: none;">抖音可用券：</view>
						<view class="select-box" v-if="douyinList.length">
							<view class="select-item flexWrapNo" v-for="(item,index) in douyinList" :key="index" @tap="selectDouyin(index)">
								<image src="../../static/order/select-icon.png" class="select-icon" v-if="item.check"></image>
								<image src="../../static/order/notselect-icon.png" class="select-icon" v-else></image>
								<text>{{item.title}}</text>
							</view>
						</view>
						<view v-else>请先添加抖音券</view>
					</view>
					<view class="remaks-box">
						备注：设置该桌台\包房可验券类型，不选则为不限制。
					</view>
				</view>
				<view class="bottom-box flexWrapNo">
					<view class="define-btn" @tap="descSetProCanDoFunction()">提交保存</view>
				</view>
				<view class="picker-box" v-if="pickerFlag">
					<view class="picker-top flexWrap">
						<view @tap="closePicker">取消</view>
						<view class="confirm-btn" @tap="confirm()">确定</view>
					</view>
					<block v-if="openPickerIndex==0">
						<picker-view  :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view">
						    <picker-view-column>
						        <view class="item" v-for="(item,index) in resourcesList" :key="index">{{item.name}}</view>
						    </picker-view-column>
						    <picker-view-column>
						        <view class="item" v-for="(item,index) in equipmentResources" :key="index">{{item.name}}</view>
						    </picker-view-column>
							<picker-view-column>
							    <view class="item" v-for="(item,index) in equipmentList" :key="index">{{item.name}}</view>
							</picker-view-column>
						</picker-view>
					</block>
					<block v-if="openPickerIndex==1">
						<picker-view  :indicator-style="indicatorStyle" :value="reversevalue" @change="bindChange1" class="picker-view">
						    <picker-view-column>
						        <view class="item" v-for="(item,index1) in resourcesLists" :key="index1">{{item.name}}</view>
						    </picker-view-column>
						    <picker-view-column>
						        <view class="item" v-for="(item,index1) in equipmentResourcess" :key="index1">{{item.name}}</view>
						    </picker-view-column>
							<picker-view-column>
							    <view class="item" v-for="(item,index1) in equipmentLists" :key="index1">{{item.name}}</view>
							</picker-view-column>
						</picker-view>
					</block>
				</view>
				
				<view class="picker-box" v-if="curtainPickerFlag">
					<view class="picker-top flexWrap">
						<view @tap="closeRollerPicker()">取消</view>
						<view class="confirm-btn" @tap="rollerConfirm()">确定</view>
					</view>
					<picker-view  :indicator-style="indicatorStyle" :value="curtainValue" @change="bindChangeRoller" class="picker-view">
					    <picker-view-column style="flex:0 0 27%;">
					        <view class="item" v-for="(item1,index1) in curtainModleList" :key="index1">{{item1.equipment_name}}</view>
					    </picker-view-column>
					    <picker-view-column style="flex:0 0 27%;">
					        <view class="item" v-for="(item2,index2) in curtainResourceList" :key="index2">{{item2.resource_name}}</view>
					    </picker-view-column>
						<picker-view-column>
						    <view class="item" v-for="(item3,index3) in curtainDidList" :key="index3">{{item3.did}}</view>
						</picker-view-column>
					</picker-view>	
				</view>
				
				<view class="mask-wrap" v-if="pickerFlag"></view>
				<niceui-popup-select ref="showAttr" :columns="attrList" :selectValue="attrId"
					:option="{label:'attr', value:'id'}" @confirm="confirmAttr">
				</niceui-popup-select>
			</view>
		</template>
	</view>
</template>

<script>
	import base from '@/common/base.js';
	export default {
		data() {
			return {
				pageOpc: 0,
				array: ['乒乓球台桌', '麻将包房'],
				attrList:[],
				attrId:[],
				attrName:"",
				index: 0,
				tableList:[
					{
						name:"乒乓球台桌"
					}
				],
				tableIndex:0,
				mahjong_price_list:[],
				mahjongPriceIndex:0,
				meituanList:[],
				douyinList:[],
				id:"",
				store_equipment_info:{},
				// 正向开关列表
				equipment_resources_list:[],
				equipmentIndex:0,
				// 正向选中
				deviceList:[],
				deviceIndex:0,
				// 逆向开关列表
				reverseList:[],
				reverseIndex:0,
				// 逆向选中
				reverseDeviceList:[],
				reverseDeviceIndex:0,
				straight_id:"",
				reverse_id:"",
				
				pickerFlag:false,
				indicatorStyle: `height: 68rpx;`,
				value:[0,0,0],
				reversevalue:[0,0,0],
				pickComfirmShow:0,
				pickComfirmShows:0,
				resourcesList:[],//一级
				resourcesLists:[],//一级
				didIndex:0,
				didIndexs:0,
				did:"",
				dids:"",
				
				equipmentResources:[],//二级
				equipmentResourcess:[],//二级
				resourcesIndex:0,
				resources:"",
				resourcess:"",
				
				equipmentList:[],//三级
				equipmentLists:[],//三级
				modelIndex:0,
				model:"",
				models:"",
				deviceArr:"",
				reverseArr:"",
				openPickerIndex:0,
				defaultDid:"",
				tqpriceList:[],
				tqpriceIndex:0,
				type:1,
				video_url:"",
				imageList: [],
				uploadList:[],
				imageLength: 5,
				
				curtainPickerFlag:false,
				curtainValue:[0,0,0],
				curtainModleList:[],  //卷帘模型数据
				curtainResourceList:[],  // 卷帘资源数据
				curtainDidList:[],  // 设备did
				jlModleValue:'',
				jlResourceValue:'',
				jlDidValue:'',
				curtainStr:'',
			}
		},
		onLoad(ops) {
			this.id=ops.id
			this.tableIndex=Number(ops.table_type)-1
			this.type=ops.type
			this.getTableInfo();
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		methods: {
			deleteVideo(){
				this.video_url=""
			},
			chooseVideo() {
				var that = this
				uni.chooseVideo({
					sourceType: ['camera', 'album'],
					success: function(res) {
						let httpsHead = 'https://moyu24h-new.oss-cn-chengdu.aliyuncs.com/'
						that.$tools.loadIng('上传中,请稍后..')
						let video_url = res.tempFilePath
						this.thumbTempFilePath = res.thumbTempFilePath
						console.log(this.thumbTempFilePath)
						base.aliyun_upload(video_url, function(r, err) {
							if (r) {
								console.log(httpsHead+r)
								that.video_url = httpsHead+r
								console.log(that.video_url+'?x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast')
								uni.hideLoading();
							}
						}, function(res) {
							console.log(res);
						}, 'mp4', 'video/')
					}
				});
			},
			chooseImage: async function() {
				var that = this
				uni.chooseImage({
					count: this.imageLength - this.imageList.length,
					extension: ['.jpg', '.png', '.jpeg'],
					success: (res) => {
						console.log(res)
						for (let i in res.tempFilePaths) {
							var imgFiles = res.tempFilePaths[i]
							let suffix = res.tempFilePaths[i].split('.')[1]
							console.log(suffix)
							if (suffix != 'jpg' && suffix != 'png' && suffix != 'jpeg') {
								this.$tools.showToast('图片仅支持jpg、jpeg、png');
								return;
							}
							that.cutImageCallback(imgFiles);
						}
						that.imageList = that.imageList.concat(res.tempFilePaths)
					}
				})
			},
			cutImageCallback(content) {
				let that = this;
				let httpsHead = 'https://moyu24h-new.oss-cn-chengdu.aliyuncs.com/'
				that.$tools.loadIng('上传中,请稍后..')
				base.aliyun_upload(content, function(r, err) {
					if (r) {
						let uploadimg = httpsHead + r
						console.log(r)
						that.uploadList = that.uploadList.concat(uploadimg);
						uni.hideLoading();
					}
				})
			},
			//删除图片
			deleteImage(index) {
				console.log(index)
				this.imageList.splice(index, 1);
				this.uploadList.splice(index, 1);
			},
			openAttr(){
				 this.$refs.showAttr.showPopup()
			},
			confirmAttr(value,data) {
			  console.log(value,data)
			  this.attrId = value
			  if(this.attrId.length>3){
				  this.$tools.showToast('标签最多选择三个')
				  return;
			  }
			  let attrName=[]
			  for (var i = 0; i <this.attrList.length; i++) {
			  	for (var j = 0; j <this.attrId.length; j++) {
			  		if (this.attrId[j]==this.attrList[i].id) {
			  			attrName.push(this.attrList[i].attr)
			  		}
			  	}
			  }
			  this.attrName=attrName.join(',')
			  console.log(this.attrName)
			  this.$refs.showAttr.closePopup()
			},
			openPicker(index){
				console.log('打开')
				this.pickerFlag=true
				this.openPickerIndex=index
				if(index==1){
					if(!this.dids){
						this.getDevices();
					}
				}else{
					if(!this.did){
						this.getDevice();
					}
				}
			},
			closePicker(){
				this.pickerFlag=false
				if(this.openPickerIndex==0){
					this.did=this.store_equipment_info.did
					if(JSON.parse(JSON.stringify(this.value))[1]==-1){
						JSON.parse(JSON.stringify(this.value))[1]=0
					}
					this.value[0]=(this.store_equipment_info.did!=null&&this.store_equipment_info.did!='null'&&this.store_equipment_info.did!='')?this.resourcesList.findIndex(item=>item.value==this.store_equipment_info.did):0
					this.value[1]=(this.store_equipment_info.resources!=null&&this.store_equipment_info.resources!='null'&&this.store_equipment_info.resources!='')?this.equipmentResources.findIndex(item=>item.value==this.store_equipment_info.resources):0
					if(this.equipmentList.length!=0){
						this.value[2]=(this.store_equipment_info.model!=null&&this.store_equipment_info.model!='null'&&this.store_equipment_info.model!='')?this.equipmentList.findIndex(item=>item.value==this.store_equipment_info.model):0
					}
					this.getDevice();
				}else{
					this.dids=this.store_equipment_info.dids
					if(JSON.parse(JSON.stringify(this.reversevalue))[1]==-1){
						JSON.parse(JSON.stringify(this.reversevalue))[1]=0
					}
					this.reversevalue[0]=(this.store_equipment_info.dids!=null&&this.store_equipment_info.dids!='null'&&this.store_equipment_info.dids!='')?this.resourcesLists.findIndex(item=>item.value==this.store_equipment_info.dids):0
					this.reversevalue[1]=(this.store_equipment_info.resourcess!=null&&this.store_equipment_info.resourcess!='null'&&this.store_equipment_info.resourcess!='')?this.equipmentResourcess.findIndex(item=>item.value==this.store_equipment_info.resourcess):0
					if(this.equipmentLists.length!=0){
						this.reversevalue[2]=(this.store_equipment_info.models!=null&&this.store_equipment_info.models!='null'&&this.store_equipment_info.models!='')?this.equipmentLists.findIndex(item=>item.value==this.store_equipment_info.models):0
					}
					this.getDevices();
				}
			},
			bindChange(e){
				console.log(this.openPickerIndex)
				let didIndex=0
				let resourcesIndex=0
				let modelIndex=0
				let did=""
				let resources=""
				let model=""
				this.value=e.detail.value
				didIndex=this.value[0]
				if(didIndex!=this.didIndex){
					console.log("this.value[1]=0")
					this.value[1]=0
				}
				this.didIndex=this.value[0]
				resourcesIndex=this.value[1]
				modelIndex=this.value[2]
				this.pickComfirmShow=1
				did=this.store_equipment_info.did
				resources=this.store_equipment_info.resources
				model=this.store_equipment_info.model
				this.did=this.resourcesList[didIndex].value
				this.resources=this.equipmentResources[resourcesIndex].value
				this.model=this.equipmentList.length!=0?this.equipmentList[modelIndex].value:""
				// if(did!=this.did){
				// 	this.value[1]=0
				// }
				this.getDevice();
			},
			bindChange1(e){
				console.log(e)
				console.log(this.openPickerIndex)
				let didIndex=0
				let resourcesIndex=0
				let modelIndex=0
				let did=""
				let resources=""
				let model=""
				this.reversevalue=e.detail.value
				didIndex=this.reversevalue[0]
				console.log(didIndex)
				console.log(this.didIndexs)
				if(didIndex!=this.didIndexs){
					this.reversevalue[1]=0
					console.log('this.reversevalue[1]=0')
				}
				this.didIndexs=this.reversevalue[0]
				resourcesIndex=this.reversevalue[1]
				modelIndex=this.reversevalue[2]
				this.pickComfirmShows=1
				did=this.store_equipment_info.dids
				resources=this.store_equipment_info.resourcess
				model=this.store_equipment_info.models
				this.dids=this.resourcesLists[didIndex].value
				this.resourcess=this.equipmentResourcess[resourcesIndex].value
				this.models=this.equipmentLists.length!=0?this.equipmentLists[modelIndex].value:""
				// if(did!=this.dids){
				// 	console.log('不想同')
				// 	this.reversevalue[1]=0
				// }
				this.getDevices();
			},
			confirm(){
				this.pickerFlag=false
				if(this.openPickerIndex==0){
					console.log(this.value)
					let didIndex=this.value[0]
					let resourcesIndex=this.value[1]
					let modelIndex=this.value[2]
					this.store_equipment_info.did=this.resourcesList[didIndex].value
					this.store_equipment_info.resources=this.equipmentResources[resourcesIndex].value
					this.store_equipment_info.model=this.equipmentList.length!=0?this.equipmentList[modelIndex].value:""
					this.deviceArr=this.resourcesList[didIndex].name+this.equipmentResources[resourcesIndex].name+(this.equipmentList.length!=0?this.equipmentList[modelIndex].name:"")
				}else{
					console.log(this.reversevalue)
					let didIndex=this.reversevalue[0]
					let resourcesIndex=this.reversevalue[1]
					let modelIndex=this.reversevalue[2]
					this.store_equipment_info.dids=this.resourcesList[didIndex].value
					this.store_equipment_info.resourcess=this.equipmentResourcess[resourcesIndex].value
					this.store_equipment_info.models=this.equipmentList.length!=0?this.equipmentList[modelIndex].value:""
					this.reverseArr=this.resourcesList[didIndex].name+this.equipmentResourcess[resourcesIndex].name+(this.equipmentLists.length!=0?this.equipmentLists[modelIndex].name:"")
				}
			},
			getDevice(){
				this.$request.post(this.$api.getDevice, {
					did:this.dids||this.did||this.defaultDid,
					store_id: uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.equipmentResources=data
						if(!this.resources&&this.equipmentResourcess.length>0){
							this.resources=this.equipmentResources[0].value
						}
						if(this.pickComfirmShow==0){
							this.value[1]=(this.store_equipment_info.resources!=null&&this.store_equipment_info.resources!='null'&&this.store_equipment_info.resources!='')?this.equipmentResources.findIndex(item=>item.value==this.store_equipment_info.resources):0
							
						}
						this.getEquipmentList();
					}
				})
			},
			getDevices(){
				this.$request.post(this.$api.getDevice, {
					did:this.dids||this.did||this.defaultDid,
					store_id: uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.equipmentResourcess=data
						if(!this.resourcess&&this.equipmentResourcess.length>0){
							this.resourcess=this.equipmentResourcess[0].value
						}
						if(this.pickComfirmShows==0){
							this.reversevalue[1]=(this.store_equipment_info.resourcess!=null&&this.store_equipment_info.resourcess!='null'&&this.store_equipment_info.resourcess!='')?this.equipmentResourcess.findIndex(item=>item.value==this.store_equipment_info.resourcess):0
							console.log(this.equipmentResourcess.findIndex(item=>item.value==this.store_equipment_info.resourcess))
							console.log(this.equipmentResourcess)
							console.log(this.store_equipment_info.resourcess)
							console.log(this.reversevalue[1]+'getDevices')
						}
						this.getEquipmentLists();
					}
				})
			},
			getEquipmentList(){
				this.$request.post(this.$api.getEquipmentList, {
					did:this.dids||this.did||this.defaultDid,
					store_id: uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.equipmentList=data
						if(!this.model){
							this.model=this.equipmentList.length!=0?this.equipmentList[0].value:""
						}
					}
				})
			},
			getEquipmentLists(){
				this.$request.post(this.$api.getEquipmentList, {
					did:this.dids||this.did||this.defaultDid,
					store_id: uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.equipmentLists=data
						if(!this.models){
							this.models=this.equipmentLists.length!=0?this.equipmentLists[0].value:""
						}
					}
				})
			},
			bindPickerChange: function(e) {
				this.index = e.detail.value
				this.store_equipment_info.type=Number(this.index)+1
				this.type=Number(this.index)+1
				this.getTableInfo();
			},
			changeTable(e){
				this.tableIndex=e.detail.value
				this.store_equipment_info.table_type=Number(this.tableIndex)+1
				this.getTableInfo();
			},
			changePrice(e){
				this.tqpriceIndex=e.detail.value
				this.store_equipment_info.tq_billing_rules=this.tqpriceList[this.tqpriceIndex].id
			},
			changeMahjong(e){
				this.mahjongPriceIndex=e.detail.value
				this.store_equipment_info.mj_billing_rules=this.mahjong_price_list[this.mahjongPriceIndex].id
			},
			selectMeituan(index){
				this.meituanList[index].check=!this.meituanList[index].check
			},
			selectDouyin(index){
				this.douyinList[index].check=!this.douyinList[index].check
			},
			changeEquipment(e){
				let index=e.target.dataset.index
				if(index==0){
					this.deviceIndex=e.detail.value
					// this.store_equipment_info.resources=this.deviceList[this.deviceIndex].resource_id
					this.straight_id=this.deviceList[this.deviceIndex].id
				}else{
					this.reverseDeviceIndex=e.detail.value
					// this.store_equipment_info.resourcess=this.reverseDeviceList[this.reverseDeviceIndex].resource_id
					this.reverse_id=this.reverseDeviceList[this.reverseDeviceIndex].id
				}
			},
			getExt(e){
				let filesIndex=e.lastIndexOf('.')
				let filesExt=e.substr(filesIndex+1)
				if(filesExt=='mp4'){
					return true
				}else{
					return false
				}
			},
			getTableInfo(){
				uni.showLoading({
					title:'加载中，请稍等...',
					mask:true
				})
				this.$request.post(this.$api.tableInfo, {
					store_id: uni.getStorageSync('store_id'),
					store_equipment_id:this.id,
					table_type:Number(this.tableIndex)+1,
					type:this.type
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						this.attrList=data.desk_label_list
						this.attrId=data.store_equipment_info.attr.map(it=>Number(it))
						let attrName=[]
						for (var i = 0; i <this.attrList.length; i++) {
							for (var j = 0; j <this.attrId.length; j++) {
								if (this.attrId[j]==this.attrList[i].id) {
									attrName.push(this.attrList[i].attr)
								}
							}
						}
						if (data.store_equipment_info.info) {
							let bannerList = data.store_equipment_info.info.split(',')
							bannerList = bannerList.map(item => {
								return {
									isVideo: this.getExt(item),
									url: item
								}
							})
							console.log(bannerList)
							bannerList.map((item,index) => {
							   if(item.isVideo){
							      this.video_url=item.url
							   }else{
								   this.imageList.push(item.url)
								   this.uploadList.push(item.url)
							   }
							})
						}
						this.tqpriceList=data.store_tqprice_list
						this.attrName=attrName.join(',')
						this.store_equipment_info=data.store_equipment_info
						this.index=Number(data.store_equipment_info.type)-1
						// this.tableIndex=Number(data.store_equipment_info.table_type)-1
						this.tqpriceIndex=this.tqpriceList.findIndex(item=>item.id==data.store_equipment_info.tq_billing_rules)
						let meituan_id=data.store_equipment_info.meituan_id?data.store_equipment_info.meituan_id.split(','):[]
						let douyin_id=data.store_equipment_info.douyin_id?data.store_equipment_info.douyin_id.split(','):[]
						for (let i in data.mei_tuan_list) {
							data.mei_tuan_list[i].check=false
						}
						for (let i in data.dou_yin_list) {
							data.dou_yin_list[i].check=false
						}
						this.meituanList=data.mei_tuan_list
						this.douyinList=data.dou_yin_list
						if(meituan_id.length!=0){
							for (var i = 0; i <this.meituanList.length; i++) {
								for (var j = 0; j <meituan_id.length; j++) {
									if (meituan_id[j]==this.meituanList[i].id) {
										this.meituanList[i].check=true
									}
								}
							}
						}
						if(douyin_id.length!=0){
							for (var i = 0; i <this.douyinList.length; i++) {
								for (var j = 0; j <douyin_id.length; j++) {
									if (douyin_id[j]==this.douyinList[i].id) {
										this.douyinList[i].check=true
									}
								}
							}
						}
						// this.equipment_resources_list=data.equipment_resources_list
						// this.equipmentIndex=(data.store_equipment_info.did!=null&&data.store_equipment_info.did!='null'&&data.store_equipment_info.did!='')?this.equipment_resources_list.findIndex(item=>item.did==data.store_equipment_info.did):0
						
						// this.deviceList=data.equipment_resources_list
						// this.deviceIndex=(data.straight_id!=null&&data.straight_id!='null'&&data.straight_id!='')?this.deviceList.findIndex(item=>item.id==data.straight_id):0
						// this.straight_id=data.straight_id
						// console.log(this.equipmentIndex)
						// console.log(this.deviceList)
						// console.log(this.deviceIndex)
						// // this.reverseList=data.equipment_resources_list
						// // this.reverseIndex=(data.store_equipment_info.dids!=null&&data.store_equipment_info.dids!='null'&&data.store_equipment_info.dids!='')?this.reverseList.findIndex(item=>item.did==data.store_equipment_info.dids):0
						
						// this.reverseDeviceList=data.equipment_resources_list
						// this.reverseDeviceIndex=(data.reverse_id!=null&&data.reverse_id!='null'&&data.reverse_id!='')?this.reverseDeviceList.findIndex(item=>item.id==data.reverse_id):0
						// this.reverse_id=data.reverse_id
						// console.log(this.reverseIndex)
						// console.log(this.reverseDeviceList)
						// console.log(this.reverseDeviceIndex)
						this.resourcesList=data.equipment_resources_list
						this.resourcesLists=data.equipment_resources_list
						this.did=(data.store_equipment_info.did!=null&&data.store_equipment_info.did!='null'&&data.store_equipment_info.did!='')?data.store_equipment_info.did:""
						this.dids=(data.store_equipment_info.dids!=null&&data.store_equipment_info.dids!='null'&&data.store_equipment_info.dids!='')?data.store_equipment_info.dids:""
						this.value[0]=(data.store_equipment_info.did!=null&&data.store_equipment_info.did!='null'&&data.store_equipment_info.did!='')?this.resourcesList.findIndex(item=>item.value==data.store_equipment_info.did):0
						this.reversevalue[0]=(data.store_equipment_info.dids!=null&&data.store_equipment_info.dids!='null'&&data.store_equipment_info.dids!='')?this.resourcesLists.findIndex(item=>item.value==data.store_equipment_info.dids):0
						
						this.jlModleValue=data.store_equipment_info.jl_model
						this.jlResourceValue=data.store_equipment_info.jl_resources
						this.jlDidValue=data.store_equipment_info.jl_did
						// this.curtainStr=data.store_equipment_info.jl_equipment_name+data.store_equipment_info.jl_resource_name+data.store_equipment_info.jl_did
								
						if(!this.did&&!this.dids){
							this.defaultDid=this.resourcesList[0].value
						}
						if(this.did){
							this.getDevice();
						}
						if(this.dids){
							this.getDevices();
						}
						
						this.getCurtainList()
						
						this.mahjong_price_list=data.mahjong_price_list
						let mahjongPriceIndex=this.mahjong_price_list.findIndex(item=>item.id==data.store_equipment_info.mj_billing_rules)
						this.mahjongPriceIndex=mahjongPriceIndex==-1?0:mahjongPriceIndex
					}
				}).finally(() => {
					setTimeout(() => {
						this.$tools.hideLoading()
					}, 1000)
				})
			},
			descSetProCanDoFunction(){
				this.$jiuaiDebounce.canDoFunction({
					key: 'descSetPro', //基于此值判断是否可以操作，如两个方法传入了同样的key，则会混淆，建议传入调用此事件的方法名，简单好梳理
					time: 2000, //如果传入time字段，则为定时器后，自动解除锁定状态，单位（毫秒）
					success: () => { //成功中调用应该操作的方法，被锁定状态不会执行此代码块内的方法
						this.descSetPro();
					}
				})
			},
			descSetPro(){
				if(!this.store_equipment_info.equipment_name){
					this.$tools.showToast('台桌名称不能为空')
					return;
				}
				if(this.$tools.containsWildcard(this.store_equipment_info.equipment_name)){
					this.$tools.showToast('台桌名称不能包含特殊字符')
					return;
				}
				let requestData={}
				let meituan_id=[]
				let douyin_id=[]
				
				for (let i in this.meituanList) {
					if(this.meituanList[i].check){
						meituan_id.push(this.meituanList[i].id)
					}
				}
				for (let i in this.douyinList) {
					if(this.douyinList[i].check){
						douyin_id.push(this.douyinList[i].id)
					}
				}
				this.store_equipment_info.meituan_id=meituan_id
				this.store_equipment_info.douyin_id=douyin_id
				this.store_equipment_info.attr=this.attrId.join(',')
				let info=[]
				if(this.video_url){
					info.unshift(this.video_url)
				}
				if(this.uploadList.length){
					info=info.concat(this.uploadList)
				}
				this.store_equipment_info.info=info.join(',')
				requestData=this.store_equipment_info
				requestData.straight_id=this.straight_id
				requestData.reverse_id=this.reverse_id
				if(this.jlDidValue){
					requestData.jl_model=this.jlModleValue
					requestData.jl_resource=this.jlResourceValue
					requestData.jl_did=this.jlDidValue
				}
				this.$request.post(this.$api.descSetPro,requestData, {
					token:true
				}).then(res => {
					if (res.code==1) {
						this.$tools.showToast('修改成功')
						let pages = getCurrentPages(); //当前页
						let beforePage = pages[pages.length - 2]; //上个页面
						beforePage.$vm.getList()
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},2000)
					}else{
						uni.hideToast();
						if(res.data==1){
							uni.showModal({
								title:'提示',
								content:res.msg+'是否前往设置?',
								success: (res) => {
									if(res.confirm){
										uni.navigateTo({
											url:'/moduleB/manage/priceSet'
										})
									}
								}
							})
						}
					}
				})
			},
			
			// 打开卷帘配置弹窗
			openRollerPicker(){
				this.curtainPickerFlag=true
			},
			
			// 卷帘获取数据
			getCurtainList(){
				this.$request.post(this.$api.curtainList,{
					store_id: uni.getStorageSync('store_id'),
					equipment_id:this.store_equipment_info.id
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.curtainModleList=data
						if(this.jlDidValue){
							let index=this.curtainModleList.findIndex(item=>item.did==this.jlDidValue)
							this.curtainValue[0]=index>=0?index:0
							this.curtainStr=this.curtainModleList[index].equipment_name+this.curtainModleList[index].resource_name+this.curtainModleList[index].did
						}
						this.rollerReset()
					}
				})
			},
			
			// 卷帘关联改变
			bindChangeRoller(e){
				this.curtainValue=e.detail.value
				this.rollerReset()
			},
			
			// 卷帘配置确定
			rollerConfirm(){
				this.curtainPickerFlag=false
				let idx=this.curtainValue[0]
				this.curtainStr=this.curtainModleList[idx].equipment_name+this.curtainModleList[idx].resource_name+this.curtainModleList[idx].did
				this.jlModleValue=this.curtainModleList[idx].equipment_model
				this.jlResourceValue=this.curtainModleList[idx].resource_id
				this.jlDidValue=this.curtainModleList[idx].did
			},
			
			// 关闭卷帘配置弹窗
			closeRollerPicker(){
				this.curtainPickerFlag=false
				if(this.jlDidValue){
					let index=this.curtainModleList.findIndex(item=>item.did==this.jlDidValue)
					this.curtainValue[0]=index>=0?index:0
					this.rollerReset()
				}
			},
			
			// 卷帘重新渲染
			rollerReset(){
				this.curtainResourceList=[]
				this.curtainDidList=[]
				this.curtainResourceList.push(this.curtainModleList[this.curtainValue[0]])
				this.curtainDidList.push(this.curtainModleList[this.curtainValue[0]])
			},
			
		}
	}
</script>

<style lang="scss">
	.picker-box{
		position: fixed !important;
		bottom: 0;
		left: 0;
		right: 0;
		margin: auto;
		background: #FFFFFF;
		z-index: 999;
		.picker-top{
			padding: 30upx 50upx;
			.confirm-btn{
				color: #26BCFD;
			}
		}
		.picker-view {
			width: 750rpx;
			height: 400rpx;
			.item {
				line-height: 68rpx;
				text-align: center;
				color: #000;
				font-size: 24upx;
			}
		}
	}
	.content {
		padding: 0 30upx;
		padding-bottom: 200upx;
		.shop-info-box {
			.info-item {
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 40upx;
				color: #FFFFFF;
				padding: 30upx 0;
				border-bottom: 1upx solid #36355E;
				&:nth-last-of-type(1){
					border-bottom: none;
				}
				picker{
					flex: 1;
				}
				.select-input{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
					flex: 1;
				}
				input {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
					flex: 1;
				}

				.icon-more {
					border-color: #FFFFFF;
				}
				.attachment-box {
					margin-top: 30upx;
					flex-wrap: wrap;
					gap: 10rpx;
					.add-btn {
						width: 162rpx;
						height: 162rpx;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						border: 1upx solid #36355E;
						position: relative;
						margin-right: 20upx;
				
						&::after {
							content: "";
							display: inline-block;
							width: 40upx;
							height: 4upx;
							background: #36355E;
							position: absolute;
							left: 0;
							right: 0;
							top: 0;
							bottom: 0;
							margin: auto;
						}
				
						&::before {
							content: "";
							display: inline-block;
							width: 4upx;
							height: 40upx;
							background: #36355E;
							position: absolute;
							left: 0;
							right: 0;
							top: 0;
							bottom: 0;
							margin: auto;
						}
					}
				
					.attachment-img {
						width: 162rpx;
						height: 162rpx;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						position: relative;
						flex: none;
						:nth-of-type(3n) {
							margin-right: 0;
						}
				
						.close-btn {
							position: absolute;
							top: -10upx;
							right: -10upx;
							width: 40upx;
							height: 40upx;
						}
					}
				}
				
				.attachment-tips {
					font-size: 24upx;
					margin-top: 20upx;
				}
				.placeholderclass {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
				}
				.select-box{
					.select-item{
						font-size: 28upx;
						color: #FFFFFF;
						margin-bottom: 20upx;
						align-items: flex-start;
						.select-icon{
							width: 40upx;
							height: 40upx;
							margin-right: 10upx;
							flex: none;
						}
					}
				}
			}
			.remaks-box{
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #82819B;
				line-height: 40rpx;
				padding-left: 138upx;
				margin-top: 12upx;
			}
		}
		.bottom-box{
			height: 120rpx;
			background: #1D1C5C;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			justify-content: center;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			.define-btn{
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 80rpx;
				width: 322rpx;
				height: 80rpx;
				background: #26BCFD;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				text-align: center;
			}
		}
	}
</style>
